package com.learning.spring.ioc.property.config;

import com.learning.spring.ioc.property.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;

/**
 * ClassName: UserConfig
 * Description:
 * Date: 2020/8/25 20:07 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
@Configuration
@PropertySource(value = "classpath:application.properties")
public class UserConfig {
    @Autowired
    Environment environment;


    @Value("${user.age}")
    private int age;


    @Bean
    public User userPropertySourceAnnotation() {
        User user = new User();
        user.setName(environment.getProperty("user.name"));
        user.setAge(age);
        return user;
    }

}
